// 封装成函数，通过修改data数据可再次调用
// 用于快速匹配输入框搜索结果
function search() {
    const searchInput = document.getElementById('inputMessage');
    const searchResults = document.getElementById('searchResults');

    searchInput.addEventListener('input', function () {
        const searchText = this.value.toLowerCase();
        const matchedResults = data.filter(item => item.toLowerCase().includes(searchText));
        displayResults(matchedResults);
    });

    function displayResults(results) {
        searchResults.innerHTML = '';
        const inputRect = searchInput.getBoundingClientRect();
        // searchResults.style.top = `${inputRect.top - searchResults.offsetHeight - 245}px`;

        results.forEach(result => {
            const li = document.createElement('li');
            li.textContent = result;
            li.addEventListener('click', function () {
                searchInput.value = result;
                searchResults.innerHTML = '';
            });
            searchResults.appendChild(li);
        });
    }
}

// 默认调用一次
search();